home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / dc14 / src / list.c < prev    next >
C/C++ Source or Header  |  1994-06-01  |  2KB  |  120 lines

  1. /*************************************
  2.    List 関連の処理をするmodule
  3. **************************************/
  4. #include<string.h>
  5. #include<direct.h>
  6. #include<dos.h>
  7. #include<direct.h>
  8. #include<stdlib.h>
  9. #include<stddef.h>
  10. #include<stdio.h>
  11. #include"list.h"
  12. #include"chain.h"
  13.  
  14. #define    TRUE    (-1)
  15. #define FALSE    0
  16.  
  17. extern    LIST    head;
  18.  
  19. /*******************************
  20.  File のlistを作ってその数を返す
  21.  *******************************/
  22. int MakeList(PARA inf)
  23. {
  24.     unsigned int dmy=0,stat=0,count=0;
  25.     char ter[13];
  26.     struct _find_t    fb;
  27.     LIST    *prev,*t;
  28.     
  29.     head.next=NULL;
  30.     _dos_setdrive(inf.drive,&dmy);
  31.     if(inf.path[0] != '\0')
  32.         if (_chdir(inf.path)==ERR){
  33.             printf("ディレクトリの指定が違います.");
  34.             exit(1);
  35.         }
  36.     
  37.     if(inf.file[0]=='\0'){
  38.         strcpy(ter,"*.doc");
  39.     }else{
  40.         strcpy(ter,inf.file);
  41.     }
  42.     
  43.     prev=&head;
  44.     stat = _dos_findfirst(ter,ALL_ATTRIBUTE,&fb);
  45.     while(stat==0){
  46.         count++;
  47.         t=(LIST *)malloc(sizeof(LIST));
  48.         if(t==NULL){
  49.             printf("Memory allocation error. \n");
  50.             exit(1);
  51.         }
  52.         prev->next=t;
  53.         t->next=NULL;
  54.         t->size=fb.size; 
  55.         t->wr_time=fb.wr_time;
  56.         t->wr_date=fb.wr_date;
  57.         t->line=0;
  58.         t->flag=FALSE;
  59.         strcpy(t->file,fb.name);
  60.         prev=t;
  61.         stat=_dos_findnext(&fb);
  62.     }
  63.     return(count);
  64. }
  65.  
  66. /*********************************************
  67. purpose:
  68.   ファイルサイズの合計がsizeに近くなるように
  69.   flagをたてる。
  70. return:
  71.   フラグを立てたファイル数
  72.   
  73.  n --> 目次のファイル数 
  74. **********************************************/
  75. int SetFlag(int size)
  76. {
  77.     int sum=HEADERSIZE,count=0;
  78.     LIST    *p;
  79.     
  80.     
  81.     for(p=head.next,count=0;p!=NULL;p=p->next){
  82.         if ((sum + (p->size) + HEADERSIZE+80+INDEXLINE*80) < size ){
  83.             p -> flag = TRUE;
  84.             sum=sum+p->size+HEADERSIZE+INDEXLINE*80+80;
  85.             count++;
  86.         }
  87.     }
  88.     return(count);
  89. }
  90.  
  91. /***************************************
  92. purpose:
  93.     既に連結が終わったファイルをリスト
  94.     から削除する関数
  95. return:
  96.     削除したファイル数
  97. ****************************************/
  98. int ClearFlag(void)
  99. {
  100.     LIST *p,*prev,*del;
  101.     int count=0;
  102.     
  103.     p=head.next;
  104.     prev=&head;
  105.     while(p!=NULL){
  106.         if( p->flag == TRUE){
  107.             prev->next=p->next;
  108.             del=p;
  109.             p=p->next;
  110.             count++;
  111.             free(del->bf);
  112.             free(del);
  113.         }else{
  114.             prev=prev->next;
  115.             p=p->next;
  116.         }
  117.     }
  118.     return(count);
  119. }
  120.